package com.jt.controller;

import com.jt.annotation.CacheFind;
import com.jt.service.ItemCatService;
import com.jt.vo.EasyUITree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/item/cat")
public class ItemCatController {

	@Autowired
	private ItemCatService itemCatService;

    @RequestMapping("/queryItemName")
    @CacheFind(key = "ITEM_CAT_NAME")
    public String findItemCatByPage(Long itemCatId) {
		return itemCatService.findItemCat(itemCatId);
	}

	/**
	 * 业务需求: 实现商品分类的展现
	 * url:		item/cat/list
	 * 参数:	parentId = 0; //查询一级商品分类菜单.
	 * 返回值结果:	List<EasyUITree>
	 * <p>
	 * 1.查询缓存,
	 * 2.判断缓存中是否有数据
	 * 3.没有数据,则查询数据库
	 * 4.有数据,则直接返回数据
	 */
	@RequestMapping("/list")
	public List<EasyUITree> findItemCatList(Long id) {
		Long parentId = id == null ? 0L : id;
		return itemCatService.findItemCatTree(parentId);
		//return itemCatService.findItemCache(parentId);
	}
}

